﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;

namespace TestMiniAccess.AccessEntity
{
    using Microsoft.VisualStudio.TestTools.UnitTesting;
    using Ruandao.MiniAccess;
    using Ruandao.MiniAccess.SqlServer;

    /// <summary>
    /// Summary description for WithoutKeyEntityTest
    /// </summary>
    [TestClass]
    public class WithoutKeyEntityTest
    {
        public WithoutKeyEntityTest()
        {
            //
            // TODO: Add constructor logic here
            //
        }

        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        //
        // You can use the following additional attributes as you write your tests:
        //
        // Use ClassInitialize to run code before running the first test in the class
        // [ClassInitialize()]
        // public static void MyClassInitialize(TestContext testContext) { }
        //
        // Use ClassCleanup to run code after all tests in a class have run
        // [ClassCleanup()]
        // public static void MyClassCleanup() { }
        //
        // Use TestInitialize to run code before running each test 
        // [TestInitialize()]
        // public void MyTestInitialize() { }
        //
        // Use TestCleanup to run code after each test has run
        // [TestCleanup()]
        // public void MyTestCleanup() { }
        //
        #endregion

        [TestMethod]
        public void InsertWithoutKeyEntityTest()
        {
            WithoutKeyEntity t1 = new WithoutKeyEntity();

            t1.Field1 = 1;
            t1.Field2 = 2;
            t1.Field3 = 3;

            int rowcount = WithoutKeyEntity.GetAllEntities().Count;

            t1.Save();

            Assert.AreEqual(rowcount + 1, WithoutKeyEntity.GetAllEntities().Count);

            WithoutKeyEntity.Delete(1, 2, 3);
            Assert.AreEqual(rowcount, WithoutKeyEntity.GetAllEntities().Count);

        }

        [TestMethod]
        public void SearchWithoutKeyEntityTest()
        {
            WithoutKeyEntity t1 = new WithoutKeyEntity();

            t1.Field1 = 1;
            t1.Field2 = 2;
            t1.Field3 = 3;

            t1.Save();
            int rowcount = WithoutKeyEntity.SearchEntities("where Field1={0} and Field2={1} and Field3={2}", 1, 2, 3).Count;

            Assert.AreEqual(true, rowcount > 0);
            
            WithoutKeyEntity.Delete(1, 2, 3);
            int rowcount2 = WithoutKeyEntity.SearchEntities("where Field1={0} and Field2={1} and Field3={2}", 1, 2, 3).Count;
            Assert.AreEqual(rowcount - 1, rowcount2 );
        }
    }
}
